package DAO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import modelo.*;


public class LoginImplementsDAO implements LoginDAO
{
    private boolean Resp;
	
    public boolean getResp() 
    {
		return Resp;
	}

	public void setResp(boolean resp) 
	{
		Resp = resp;
	}

	public boolean conAtendente(String usuario, String senha)
	{      
    	String sqlSelect = "SELECT COUNT(*) FROM login WHERE (user = ? AND pass = ?);";
		PreparedStatement stm = null;
		ResultSet rs = null;
		AcessoBD bd = new AcessoBD();
		Connection conn = null;
	    try 
		{
			conn = bd.obtemConexao();
			stm = conn.prepareStatement(sqlSelect);
			stm.setString(1, usuario);
			stm.setString(2, senha);
			rs = stm.executeQuery(); 
			
			if(rs.next() && rs != null)
			{
				this.setResp(rs.getBoolean(1));	
			}
		}
		catch (Exception e) 
		{
            e.printStackTrace();
			try 
			{
				conn.rollback();
			} 
			catch (SQLException e1) 
			{
				System.out.print(e1.getStackTrace());
			}
		} 
		finally 
		{
			if (stm != null) 
			{
				try 
				{
					stm.close();
				} 
				catch (SQLException e1) 
				{
					System.out.print(e1.getStackTrace());
				}
			}
		}
	    return Resp;
   }
}